/* 
  [00:00.000] 作曲 : 许嵩
  [00:01.000] 作词 : 许嵩
  [00:22.240]天空好想下雨
  [00:24.380]我好想住你隔壁
*/
// const parseExp = /\[([0-9]{2}):([0-9]{2})\.([0-9]{2,3})\]/

// const parseExp = /\[(\d{2}):(\d{2})\.(\d{2,3k]})\]/;
// export function parseLyric(lyricString) {
//     const lineString = lyricString.split("\n");
//     console.log(lineString);
//     const lyrics = [];
//     for (let line of lineString) {
//         if (line) {
//             const res = parseExp.exec(line);
//             if (res) {
//                 const time1 = res[1] * 1000 * 60;
//                 const time2 = res[2] * 1000;
//                 let time3 = res[3];
//                 time3 = time3.length === 3 ? time3 * 1 : time3 * 10;
//                 const content = line.replace(res[0], "").trim();
//                 if (content) {
//                     lyrics.push({
//                         time: time1 + time2 + time3,
//                         content
//                     });
//                 }
//             }
//         }
//     }
//     console.log(lyrics);
//     return lyrics;
// }

const parseExp = /\[(\d{2}):(\d{2})\.(\d{2,3})\]/;

export function parseLyric(lyricString) {
    const lyrLine = lyricString.split("\n");
    let lyrics = [];

    for (let line of lyrLine) {
        if (line) {
            const res = parseExp.exec(line);
            if (res) {
                const time1 = res[1] * 1000 * 60;
                const time2 = res[2] * 1000;
                let time3 = res[3];

                time3 = time3.length === 3 ? time3 * 1 : time3 * 10;
                const content = line.replace(res[0], "").trim();
                if (content) {
                    lyrics.push({
                        totalTime: time1 + time2 + time3,
                        content
                    });
                }
            }
        }
    }

    return lyrics;
}